Dead Stone Algorithm (DSA) pseudo code

The process of removing dead stones is essentialy recursive. However, Ti BASIC does
not allow this type of recusion. So the idea behind my algorithm is to build up a
list of stones to be erased. The algorithm goes down this list and for every stone
on the list, it looks at its 4 neighbors. If the neighbor is also of the right color,
it adds it to the end of the list. If one of the neighbors is empty, then the list
is cleared and the search is abandoned. Once the agorithm gets to the end of the
list, then the stones on the list are deleted. Of course, this whole algorithm will
have to be implemented 4 times: once for each of the placed stone's neighbors. 

NOTE: I numbered the for loops for clarity 

 For_1 (the 4 neighbors of the placed stone) ;goes around the placed stone
	clear list
	if (stone is target color)
	Then
		add the stone to list
		For_2 (X,1,size of list) ;goes down the list of stones in the group
			For_3 (the 4 neighbors of X) ;goes around the stones in the list
				if (neighbor is target color)
				Then
					If (neighbor is not on list)
					Then
						Add stone to list
					End
				End
				if (neighbor is empty) ;group has liberty
				then
					break For_2
					break For_3
				End
			End_for_3
		End_for_2
	erase all stones on the list
	End
 End_for_1

-----------------------------------------------------------------------
Actual Ti BASIC code from program

\comment= if location to place stone is empty
If [G](11-Y/6,X/6+1)=0
Then
	Text(1,61,"  WAIT "
	If T=2
	Then
		\comment= draw white stone
		Line(X-2,Y-1,X-2,Y+1
		Line(X-1,Y+2,X+1,Y+2
		Line(X+2,Y+1,X+2,Y-1
		Line(X+1,Y-2,X-1,Y-2
		Line(X-1,Y,X+1,Y,0
		Line(X,Y+1,X,Y-1,0
		\comment= toggle turn
		1\->\T
		\comment= put stone into matrix
		2\->\[G](11-Y/6,X/6+1)
	Else
		\comment= draw black stone
		Line(X-2,Y+1,X-2,Y-1
		Line(X-1,Y+2,X-1,Y-2
		Line(X+1,Y+2,X+1,Y-2
		Line(X+2,Y+1,X+2,Y-1
		Line(X,Y+2,X,Y-2
		\comment= put stone into matrix
		1\->\[G](11-Y/6,X/6+1)
		\comment= don't change color if handicap stones left
		If H>1
		Then
			H-1\->\H
			Text(1,61,"BLACK
			\comment= break to 2 so no DSA
			Goto 2
		End
		2\->\T
	End

	\comment= start DSA
	0\->\D
	\(-)\1\->\E
	\comment= iterate around the placed stone
	For(F,1,4)
		{1,2}\->\dim([H])
		\comment= if stone is of target color
		If ([G](11-Y/6+D,X/6+1+E)=T)
		Then
			\comment= add stone to top of list
			11-Y/6+D\->\[H](1,1)
			X/6+1+E\->\[H](1,2)
			1\->\L
			1\->\G
			\comment= iterate through the stones in the list
			While G\<=\L
				0\->\M
				\(-)\1\->\N
				1\->\Z
				\comment= iterate around each stone
				While Z\<=\4
					\comment= if neighbor is also of target color
					If ([G]([H](G,1)+M,[H](G,2)+N)=T)
					Then
						1\->\J
						1\->\I
						\comment= iterate through list to check if the
						\comment= stone is already on there
						While I\<=\L and J=1
							\comment= if stone is on list
							If (([H](G,1)+M=[H](I,1)) and ([H](G,2)+N)=[H](I,2))
							Then
								\comment= break loop and set J
								0\->\J
							End
							I+1\->\I
						End
						\comment= if stone was not on list already
						If (J=1)
						Then
							\comment= add stone to bottom of list
							L+1\->\L
							{L,2}\->\dim([H])
							[H](G,1)+M\->\[H](L,1)
							[H](G,2)+N\->\[H](L,2)
						End
					End
					\comment= if neighbor is empty
					If ([G]([H](G,1)+M,[H](G,2)+N)=0)
					Then
						\comment= group has liberty
						\comment= break all the way out to F loop
						0\->\L
						5\->\Z
					End
					M\->\J
					N\->\M
					\(-)\1*J\->\N
					Z+1\->\Z
				End
				1+G\->\G
			End
			\comment= if there are stones in the list to erase
			If (L>0)
			Then
				\comment= iterate through list
				For(J,1,L)
					\comment= erase stone
					6*([H](J,2)-1)\->\M
					6*(11-[H](J,1))\->\N
					Line(M-2,N+1,M-2,N-1,0
					Line(M-1,N+2,M-1,N-2,0
					Line(M+1,N+2,M+1,N-2,0
					Line(M+2,N+1,M+2,N-1,0
					Line(M-2,N,M+2,N
					Line(M,N+1,M,N-1
					If M=54:Line(M+1,N,M+2,N,0
					If M=6:Line(M-1,N,M-2,N,0
					If N=54:Line(M,N+1,M,N+2,0
					If N=6:Line(M,N-1,M,N-2,0
					0\->\[G]([H](J,1),[H](J,2))
				End
			End
			\comment= update prisoner counters
			If T=2:O+L\->\O
			If T=1:P+L\->\P
		End
		D\->\J
		E\->\D
		\(-)\1*J\->\E
	End
	\comment= end DSA
	If T=1
	Then
		Text(1,61,"BLACK
		Text(47,87,P
	Else
		Text(1,61,"WHITE
		Text(47,68,O
	End
End
